using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the MessagingMailer class.
	/// </summary>
	[Serializable]
	public partial class MessagingMailerCollection : ActiveList<MessagingMailer,MessagingMailerCollection> 
	{	   
		public MessagingMailerCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Messaging_Mailer table.
	/// </summary>
	[Serializable]
	public partial class MessagingMailer : ActiveRecord<MessagingMailer>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public MessagingMailer()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public MessagingMailer(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public MessagingMailer(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public MessagingMailer(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Messaging_Mailer", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarMailerID = new TableSchema.TableColumn(schema);
				colvarMailerID.ColumnName = "mailerID";
				colvarMailerID.DataType = DbType.Int32;
				colvarMailerID.MaxLength = 0;
				colvarMailerID.AutoIncrement = true;
				colvarMailerID.IsNullable = false;
				colvarMailerID.IsPrimaryKey = true;
				colvarMailerID.IsForeignKey = false;
				colvarMailerID.IsReadOnly = false;
				colvarMailerID.DefaultSetting = @"";
				colvarMailerID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMailerID);
				
				TableSchema.TableColumn colvarMailerName = new TableSchema.TableColumn(schema);
				colvarMailerName.ColumnName = "mailerName";
				colvarMailerName.DataType = DbType.String;
				colvarMailerName.MaxLength = 50;
				colvarMailerName.AutoIncrement = false;
				colvarMailerName.IsNullable = false;
				colvarMailerName.IsPrimaryKey = false;
				colvarMailerName.IsForeignKey = false;
				colvarMailerName.IsReadOnly = false;
				colvarMailerName.DefaultSetting = @"";
				colvarMailerName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMailerName);
				
				TableSchema.TableColumn colvarToList = new TableSchema.TableColumn(schema);
				colvarToList.ColumnName = "toList";
				colvarToList.DataType = DbType.String;
				colvarToList.MaxLength = 500;
				colvarToList.AutoIncrement = false;
				colvarToList.IsNullable = true;
				colvarToList.IsPrimaryKey = false;
				colvarToList.IsForeignKey = false;
				colvarToList.IsReadOnly = false;
				colvarToList.DefaultSetting = @"";
				colvarToList.ForeignKeyTableName = "";
				schema.Columns.Add(colvarToList);
				
				TableSchema.TableColumn colvarCcList = new TableSchema.TableColumn(schema);
				colvarCcList.ColumnName = "ccList";
				colvarCcList.DataType = DbType.String;
				colvarCcList.MaxLength = 500;
				colvarCcList.AutoIncrement = false;
				colvarCcList.IsNullable = true;
				colvarCcList.IsPrimaryKey = false;
				colvarCcList.IsForeignKey = false;
				colvarCcList.IsReadOnly = false;
				colvarCcList.DefaultSetting = @"";
				colvarCcList.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCcList);
				
				TableSchema.TableColumn colvarFromName = new TableSchema.TableColumn(schema);
				colvarFromName.ColumnName = "fromName";
				colvarFromName.DataType = DbType.String;
				colvarFromName.MaxLength = 50;
				colvarFromName.AutoIncrement = false;
				colvarFromName.IsNullable = false;
				colvarFromName.IsPrimaryKey = false;
				colvarFromName.IsForeignKey = false;
				colvarFromName.IsReadOnly = false;
				colvarFromName.DefaultSetting = @"";
				colvarFromName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFromName);
				
				TableSchema.TableColumn colvarFromEmail = new TableSchema.TableColumn(schema);
				colvarFromEmail.ColumnName = "fromEmail";
				colvarFromEmail.DataType = DbType.String;
				colvarFromEmail.MaxLength = 50;
				colvarFromEmail.AutoIncrement = false;
				colvarFromEmail.IsNullable = false;
				colvarFromEmail.IsPrimaryKey = false;
				colvarFromEmail.IsForeignKey = false;
				colvarFromEmail.IsReadOnly = false;
				colvarFromEmail.DefaultSetting = @"";
				colvarFromEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFromEmail);
				
				TableSchema.TableColumn colvarSubject = new TableSchema.TableColumn(schema);
				colvarSubject.ColumnName = "subject";
				colvarSubject.DataType = DbType.String;
				colvarSubject.MaxLength = 50;
				colvarSubject.AutoIncrement = false;
				colvarSubject.IsNullable = false;
				colvarSubject.IsPrimaryKey = false;
				colvarSubject.IsForeignKey = false;
				colvarSubject.IsReadOnly = false;
				colvarSubject.DefaultSetting = @"";
				colvarSubject.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSubject);
				
				TableSchema.TableColumn colvarMessageBody = new TableSchema.TableColumn(schema);
				colvarMessageBody.ColumnName = "messageBody";
				colvarMessageBody.DataType = DbType.String;
				colvarMessageBody.MaxLength = 1073741823;
				colvarMessageBody.AutoIncrement = false;
				colvarMessageBody.IsNullable = false;
				colvarMessageBody.IsPrimaryKey = false;
				colvarMessageBody.IsForeignKey = false;
				colvarMessageBody.IsReadOnly = false;
				colvarMessageBody.DefaultSetting = @"";
				colvarMessageBody.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMessageBody);
				
				TableSchema.TableColumn colvarIsHTML = new TableSchema.TableColumn(schema);
				colvarIsHTML.ColumnName = "isHTML";
				colvarIsHTML.DataType = DbType.Boolean;
				colvarIsHTML.MaxLength = 0;
				colvarIsHTML.AutoIncrement = false;
				colvarIsHTML.IsNullable = false;
				colvarIsHTML.IsPrimaryKey = false;
				colvarIsHTML.IsForeignKey = false;
				colvarIsHTML.IsReadOnly = false;
				
						colvarIsHTML.DefaultSetting = @"((0))";
				colvarIsHTML.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsHTML);
				
                //TableSchema.TableColumn colvarIsSystemMailer = new TableSchema.TableColumn(schema);
                //colvarIsSystemMailer.ColumnName = "isSystemMailer";
                //colvarIsSystemMailer.DataType = DbType.Boolean;
                //colvarIsSystemMailer.MaxLength = 0;
                //colvarIsSystemMailer.AutoIncrement = false;
                //colvarIsSystemMailer.IsNullable = false;
                //colvarIsSystemMailer.IsPrimaryKey = false;
                //colvarIsSystemMailer.IsForeignKey = false;
                //colvarIsSystemMailer.IsReadOnly = false;
				
                //        colvarIsSystemMailer.DefaultSetting = @"((0))";
                //colvarIsSystemMailer.ForeignKeyTableName = "";
                //schema.Columns.Add(colvarIsSystemMailer);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "createdOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "createdBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "modifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "modifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Messaging_Mailer",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("MailerID")]
		public int MailerID 
		{
			get { return GetColumnValue<int>(Columns.MailerID); }

			set { SetColumnValue(Columns.MailerID, value); }

		}

		  
		[XmlAttribute("MailerName")]
		public string MailerName 
		{
			get { return GetColumnValue<string>(Columns.MailerName); }

			set { SetColumnValue(Columns.MailerName, value); }

		}

		  
		[XmlAttribute("ToList")]
		public string ToList 
		{
			get { return GetColumnValue<string>(Columns.ToList); }

			set { SetColumnValue(Columns.ToList, value); }

		}

		  
		[XmlAttribute("CcList")]
		public string CcList 
		{
			get { return GetColumnValue<string>(Columns.CcList); }

			set { SetColumnValue(Columns.CcList, value); }

		}

		  
		[XmlAttribute("FromName")]
		public string FromName 
		{
			get { return GetColumnValue<string>(Columns.FromName); }

			set { SetColumnValue(Columns.FromName, value); }

		}

		  
		[XmlAttribute("FromEmail")]
		public string FromEmail 
		{
			get { return GetColumnValue<string>(Columns.FromEmail); }

			set { SetColumnValue(Columns.FromEmail, value); }

		}

		  
		[XmlAttribute("Subject")]
		public string Subject 
		{
			get { return GetColumnValue<string>(Columns.Subject); }

			set { SetColumnValue(Columns.Subject, value); }

		}

		  
		[XmlAttribute("MessageBody")]
		public string MessageBody 
		{
			get { return GetColumnValue<string>(Columns.MessageBody); }

			set { SetColumnValue(Columns.MessageBody, value); }

		}

		  
		[XmlAttribute("IsHTML")]
		public bool IsHTML 
		{
			get { return GetColumnValue<bool>(Columns.IsHTML); }

			set { SetColumnValue(Columns.IsHTML, value); }

		}

		  
		[XmlAttribute("IsSystemMailer")]
		public bool IsSystemMailer 
		{
			get { return GetColumnValue<bool>(Columns.IsSystemMailer); }

			set { SetColumnValue(Columns.IsSystemMailer, value); }

		}

		
		
		//private DateTime? propCreatedOn;
		[XmlAttribute("CreatedOn")]
		public DateTime CreatedOn 
		{
			get
			{
			DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!propCreatedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propCreatedOn.Value;
			}

		   set { SetColumnValue(Columns.CreatedOn, value); }

		}

		
		[XmlIgnore]
		public bool CreatedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("createdOn") != null; }

			set
			{
				DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!value)
					SetColumnValue(Columns.CreatedOn, null);
				else if (value && !propCreatedOn.HasValue)
					SetColumnValue(Columns.CreatedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }

			set { SetColumnValue(Columns.CreatedBy, value); }

		}

		
		
		//private DateTime? propModifiedOn;
		[XmlAttribute("ModifiedOn")]
		public DateTime ModifiedOn 
		{
			get
			{
			DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!propModifiedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propModifiedOn.Value;
			}

		   set { SetColumnValue(Columns.ModifiedOn, value); }

		}

		
		[XmlIgnore]
		public bool ModifiedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("modifiedOn") != null; }

			set
			{
				DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!value)
					SetColumnValue(Columns.ModifiedOn, null);
				else if (value && !propModifiedOn.HasValue)
					SetColumnValue(Columns.ModifiedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>(Columns.ModifiedBy); }

			set { SetColumnValue(Columns.ModifiedBy, value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varMailerName,string varToList,string varCcList,string varFromName,string varFromEmail,string varSubject,string varMessageBody,bool varIsHTML,bool varIsSystemMailer,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			MessagingMailer item = new MessagingMailer();
			
			item.MailerName = varMailerName;
			
			item.ToList = varToList;
			
			item.CcList = varCcList;
			
			item.FromName = varFromName;
			
			item.FromEmail = varFromEmail;
			
			item.Subject = varSubject;
			
			item.MessageBody = varMessageBody;
			
			item.IsHTML = varIsHTML;
			
			item.IsSystemMailer = varIsSystemMailer;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varMailerID,string varMailerName,string varToList,string varCcList,string varFromName,string varFromEmail,string varSubject,string varMessageBody,bool varIsHTML,bool varIsSystemMailer,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			MessagingMailer item = new MessagingMailer();
			
				item.MailerID = varMailerID;
			
				item.MailerName = varMailerName;
			
				item.ToList = varToList;
			
				item.CcList = varCcList;
			
				item.FromName = varFromName;
			
				item.FromEmail = varFromEmail;
			
				item.Subject = varSubject;
			
				item.MessageBody = varMessageBody;
			
				item.IsHTML = varIsHTML;
			
				item.IsSystemMailer = varIsSystemMailer;
			
				item.CreatedOn = varCreatedOn;
			
				item.CreatedBy = varCreatedBy;
			
				item.ModifiedOn = varModifiedOn;
			
				item.ModifiedBy = varModifiedBy;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn MailerIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn MailerNameColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn ToListColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn CcListColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn FromNameColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn FromEmailColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn SubjectColumn
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        public static TableSchema.TableColumn MessageBodyColumn
        {
            get { return Schema.Columns[7]; }

        }

        
        
        
        public static TableSchema.TableColumn IsHTMLColumn
        {
            get { return Schema.Columns[8]; }

        }

        
        
        
        public static TableSchema.TableColumn IsSystemMailerColumn
        {
            get { return Schema.Columns[9]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[10]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[11]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedOnColumn
        {
            get { return Schema.Columns[12]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedByColumn
        {
            get { return Schema.Columns[13]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string MailerID = @"mailerID";
			 public static string MailerName = @"mailerName";
			 public static string ToList = @"toList";
			 public static string CcList = @"ccList";
			 public static string FromName = @"fromName";
			 public static string FromEmail = @"fromEmail";
			 public static string Subject = @"subject";
			 public static string MessageBody = @"messageBody";
			 public static string IsHTML = @"isHTML";
			 public static string IsSystemMailer = @"isSystemMailer";
			 public static string CreatedOn = @"createdOn";
			 public static string CreatedBy = @"createdBy";
			 public static string ModifiedOn = @"modifiedOn";
			 public static string ModifiedBy = @"modifiedBy";
						
		}

		#endregion
		
		
		
	}

}

